package cb.wzby;

import java.util.ArrayList;
import java.util.LinkedList;

public class LinkedList2 {
    public static void main(String[] args) {
        int size = 20000;
        long st = System.currentTimeMillis();
        //.currentTimeMillis() 方法返回一个long类型的值
        var l1 = new ArrayList<String>();
        //var定义局部变量
        for (int i = 0; i <= size; i++) {
            l1.add(0, "l1" + i);
        }
        long et = System.currentTimeMillis();
        System.out.printf("List:%d %n", et - st);

        st = System.currentTimeMillis();
        var l2 = new LinkedList<String>();

        for (int i = 0; i <= size; i++) {
            l2.addFirst("l2" + i);
        }
        et = System.currentTimeMillis();
        System.out.printf("LinkedList: %d %n",et-st);


        //l1(ArrayList)
        st = System.currentTimeMillis();
        for (int i=0;i <= size; i++){
            l1.get(i);
        }
        et = System.currentTimeMillis();
        System.out.printf("List:%d %n",et-st);
        //l2(LinkedList)
        st = System.currentTimeMillis();
        var l3 = new ArrayList<String>(l2);
        //  将LinkedList转换到ArraytList
        for (int i =0;i <= size; i++){
            l3.get(i);
        }
        et = System.currentTimeMillis();
        System.out.printf("LinkedList: %d %n",et-st);
    }
}
